import View from "./ExampleGridFunctionPageEdit.view";

interface INP {

}

@YvanUI.BizModule()
export default class Module extends View<Module, INP> {

    originData: any[] = [];
    gridData: any[] = [];

    onLoad(): void {
        super.onLoad();
        for (let index = 0; index < 200; index++) {
            const value = parseInt((Math.random() * 1000).toString()) % 2;
            const element = {
                'user_id': 'USER000000' + index,
                'login_name': 'admin' + index,
                'staff_name': '管理员' + index,
                'gender': value ? "M" : "F",
                'duty': '系统管理员' + index,
                'mobile': '17671794087',
                'user_state': value,
                'login_count': parseInt((Math.random() * 1000).toString()),
                'birthday': '1993-10-0' + index % 30,
                'last_login_time': 1559642281000,
                'create_at': 1559642281000,
                'update_at': 1559642281000,
                'ui_style': value ? 'light' : 'dark'
            };
            this.originData.push(element);
        }
        this.gridData = this.originData;
    }

    getGridDataSource(sender: YvanUI.CtlGrid, params: YvanUI.GridDataSourceStaticFunctionParam) {
        return params.successCallback(this.gridData, this.gridData.length);
    }

    @YvanUI.Watch('query.f1')
    f1Change(v) {
        this.gridData = this.originData.filter(item => {
            return item.login_name.indexOf(v) !== -1
        });
        this.refs.theGrid.reload();
    }

    gridRowDetail(sender: YvanUI.CtlGrid, args: YvanUI.CtlGridRowButtonClickArgs) {
        YvanUI.msg(`查看行详情 ${args.data.user_id}`);
    }

    gridDelete(sender: YvanUI.CtlGrid, args: YvanUI.CtlGridRowButtonClickArgs) {
        YvanUI.confirm(`真的要删除 "${args.data.staff_name}" ?`).then(() => {
            YvanUI.msg(`行删除 ${args.data.user_id}`);
        });
    }
}